<script setup lang="ts">
import { useDesign } from '@/hooks/useDesign';
import { useAppStore } from '@/store/modules/app';
import { snakeCase } from 'change-case';
import { ElScrollbar } from 'element-plus';
import { storeToRefs } from 'pinia';
import { ref } from 'vue';
import { LoginForm, RegisterForm } from './components';
import ThemeSwitch from '@/components/ThemeSwitch/src/ThemeSwitch.vue';

const prefixCls = useDesign().getPrefixCls('login');
const { title } = storeToRefs(useAppStore());

const isLogin = ref(true);
</script>
<template>
  <div :class="prefixCls" class="h-full relative lt-xl:bg-[var(--login-bg-color)] lt-sm:px-10px lt-md:px-10px lt-xl:px-10px">
    <ElScrollbar class="h-full">
      <div class="relative flex mx-auto min-h-100vh">
        <div :class="`${prefixCls}__left flex-1 bg-gray-500 bg-opacity-20 relative p-30px lt-xl:hidden`">
          <div class="flex text-white relative items-center">
            <img src="@/assets/vue.svg" alt="logo" class="w-48px h-48px mr-10px" />
            <span class="text-20px font-bold">{{ snakeCase(title) }}</span>
          </div>
          <div class="flex items-center flex-center h-[calc(100%-60px)]">
            <TransitionGroup appear tag="div" enter-active-class="animate__animated animate__bounceInLeft">
              <img src="@/assets/login-box-bg.svg" alt="login-box-bg" class="w-350px pointer-events-none" key="img" />
              <div class="text-3xl text-white" key="title">欢迎使用本系统</div>
              <div class="mt-5 font-normal text-white text-14px" key="subTitle">本系统开箱即用</div>
            </TransitionGroup>
          </div>
        </div>
        <div class="flex-1 p-30px lt-sm:p-10px dark:bg-[var(--login-bg-color)] relative">
          <div class="flex items-center justify-between text-white at-2xl:justify-end at-xl:justify-end">
            <div class="flex text-white relative items-center at-xl:hidden at-2xl:hidden">
              <img src="@/assets/vue.svg" alt="logo" class="w-48px h-48px mr-10px" />
              <span class="text-20px font-bold">{{ snakeCase(title) }}</span>
            </div>
            <div class="flex items-center">
              <ThemeSwitch />
            </div>
          </div>
          <!-- form -->
          <Transition appear tag="div" enter-active-class="animate__animated animate__bounceInRight">
            <div class="w-full h-full flex items-center m-auto at-xl:max-w-500px at-md:max-w-500px at-lg:max-w-500px">
              <LoginForm v-if="isLogin" class="p-20px h-auto m-auto lt-xl:rounded-3xl lt-xl:light:bg-white" @to-register="isLogin = false" />
              <RegisterForm v-else class="p-20px h-auto m-auto lt-xl:rounded-3xl lt-xl:light:bg-white" @to-login="isLogin = true" />
            </div>
          </Transition>
        </div>
      </div>
    </ElScrollbar>
  </div>
</template>

<style lang="less" scoped>
@prefix-cls: ~'@{adminNamespace}-login';

.@{prefix-cls} {
  overflow: auto;

  &__left {
    &::before {
      position: absolute;
      top: 0;
      left: 0;
      z-index: -1;
      width: 100%;
      height: 100%;
      background-image: url('@/assets/svgs/login-bg.svg');
      background-position: center;
      background-repeat: no-repeat;
      content: '';
    }
  }
}
</style>
